<template>
  <div>
    {{ timeMsg }}
  </div>
</template>

<script>
import { reactive, toRefs, onMounted } from "vue";
export default {
  setup() {
    const state = reactive({
      // reactive响应式
      timeMsg: new Date(), // 读取当前时间
    });
    onMounted(() => {
      setInterval(function() {
        // 定时1秒钟读取时钟一次，改变数据
        state.timeMsg = new Date();
      }, 1000);
    });
    return {
      ...toRefs(state),
    };
  },
};
</script>
